//
//  LSZAudioSermonsVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/18.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZAudioSermonsVC.h"
#import "LCFloatingWindow.h"
#import "LSZAudioSermonsVC+LCAVPlay.h"
#import "JKSongsMessStatus.h"
#import "NetworkTool+LCAVPlay.h"
@interface LSZAudioSermonsVC ()
{
    NSInteger lastClickRow;//记录上次点击的是那个区

}
@property(nonatomic,assign) NSInteger cliclMoveWhereRow;//排行榜用
@end

@implementation LSZAudioSermonsVC

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [LCFloatingWindow sharedInstance].hidden = NO;
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [LCFloatingWindow sharedInstance].hidden = YES;
    if(self.viewSharePopover.hidden == NO){
        self.viewSharePopover.hidden = YES;
        self.viewLow.hidden = YES;
        self.butCancel.hidden = YES;
    }
}
#pragma mark - 赞美诗歌
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"音频讲道";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.arrayChoose = @[@"热门",@"讲员",@"机构",@"类别"];
    [self setTableview];

    self.mutArrayData = [[NSMutableArray alloc]init];
    self.numberComeIn = @"5";
    self.numberPage = 1;
    [self loadMusicPriestPreached:@"hotmusic"];
    [self creareAVPlay];//取title的值进行判断
    self.viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO;
    self.numberRow = -1;
    [self addNSNotificationCenter];
}
#pragma mark - 如果是牧师讲道
-(void)priestSaysTopView
{
    UIView * viewTop= [[UIView alloc]initWithFrame:CGRectMake(0,NAVIGATION_BAR_HEIGHT, ScreenWidth, 55)];
    viewTop.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewTop];
    self.viewSmall= [[UIView alloc]initWithFrame:CGRectMake(20, 10, ScreenWidth-40, 40)];
    [self.viewSmall.layer setCornerRadius:5];
    [self.viewSmall.layer setMasksToBounds:YES];
    [self.viewSmall.layer setBorderWidth:1.0];
    self.viewSmall.layer.borderColor=navColor.CGColor;
    [viewTop addSubview:self.viewSmall];
    for (int i = 0; i<4; i++) {
        UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(i *self.viewSmall.frame.size.width/4, 0, self.viewSmall.frame.size.width/4, 40)];
        button.tag = 10+i;
        if (i == 0) {
            self.AudioNumberClass = 1;
            button.backgroundColor = navColor;
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            button.backgroundColor = [UIColor whiteColor];
            [button setTitleColor:navColor forState:UIControlStateNormal];
        }
        [button setTitle:[NSString stringWithFormat:@"%@",self.arrayChoose[i]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickChooseAudio:) forControlEvents:UIControlEventTouchUpInside];
        [self.viewSmall addSubview:button];
    }
    [LSZSpecialPackaging addThreadWithOtherRGB:self.viewSmall A:self.viewSmall.frame.size.width/4 B:0 C:1 D:self.viewSmall.frame.size.height R:228 G:83 BB:77];
    [LSZSpecialPackaging addThreadWithOtherRGB:self.viewSmall A:self.viewSmall.frame.size.width/2 B:0 C:1 D:self.viewSmall.frame.size.height R:228 G:83 BB:77];
    [LSZSpecialPackaging addThreadWithOtherRGB:self.viewSmall A:3*self.viewSmall.frame.size.width/4 B:0 C:1 D:self.viewSmall.frame.size.height R:228 G:83 BB:77];
}
#pragma mark - 表的布局_______________________
-(void)setTableview
{
    self.tableViewAudio = [[UITableView  alloc]initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, ScreenWidth, ScreenHeight-NAVIGATION_BAR_HEIGHT-60) style:UITableViewStylePlain];
    self.tableViewAudio.frame = CGRectMake(0, 55+NAVIGATION_BAR_HEIGHT, ScreenWidth, ScreenHeight-55-NAVIGATION_BAR_HEIGHT-60-HOME_INDICATOR_HEIGHT);
    [self priestSaysTopView];
    self.tableViewAudio.dataSource = self;
    self.tableViewAudio.delegate = self;
    //添加以下代码关闭估算行高
    self.tableViewAudio.estimatedRowHeight = 0;
    self.tableViewAudio.estimatedSectionHeaderHeight = 0;
    self.tableViewAudio.estimatedSectionFooterHeight = 0;
    [self.view addSubview:self.tableViewAudio];

    [self.tableViewAudio registerClass:[LSZRandombroadcastHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZRandombroadcastHeaderCell"];
    [self.tableViewAudio registerClass:[LSZAudioFrequencyTableViewCell class] forCellReuseIdentifier:@"LSZAudioFrequencyTableViewCell"];
    [self.tableViewAudio registerClass:[LSZNewWithPlusSignAudioTableViewCell class] forCellReuseIdentifier:@"LSZNewWithPlusSignAudioTableViewCell"];
    [self tableviewData];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if([self.numberComeIn isEqualToString:@"6"]||[self.numberComeIn isEqualToString:@"7"]||[self.numberComeIn isEqualToString:@"8"]){
        return 0.001;
    }else{
        return  40;
    }
}
#pragma mark - 音频有几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if([self.numberComeIn isEqualToString:@"6"]||[self.numberComeIn isEqualToString:@"7"]||[self.numberComeIn isEqualToString:@"8"]){
        UITableViewHeaderFooterView * headerCell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"headerCell"];
        if (!headerCell) {
            headerCell = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"headerCell"];
        }
        return headerCell;
    }
    else{
        LSZRandombroadcastHeaderCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZRandombroadcastHeaderCell"];
        if (!cell) {
            cell = [[LSZRandombroadcastHeaderCell alloc]initWithReuseIdentifier:@"LSZRandombroadcastHeaderCell"];
        }
        UITapGestureRecognizer * singleTapimageView = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickButRandom:)];
        [cell.imageViewPlay addGestureRecognizer:singleTapimageView];

        UITapGestureRecognizer * singleTaplabel = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickButRandom:)];
        [cell.label addGestureRecognizer:singleTaplabel];

        [cell.butPaly addTarget:self action:@selector(clickButRandom:) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
}
#pragma mark - 点击随机播放
-(void)clickButRandom:(UIButton *)but
{
    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
    _LCPlayer.songs = playlistTest.allSongs;
    _LCPlayer.listStatus = LCMusicListStatusAllCycle;//现在是循环播放
    [_LCPlayer playAtIndex:0 isSelectPlay:YES];
}
#pragma mark - 音频的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZAudioFrequencyTableViewCell * cell = [[LSZAudioFrequencyTableViewCell alloc]initWithNumberAudioFrequency:1];
    if(self.mutArrayData.count >0){
        LSZPriestPreachedAudioMg * audioMg = nil;
        audioMg =self.mutArrayData[indexPath.row];
        cell.labelNumber.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row+1];
        [cell.imageViewAudio                                 sd_setImageWithURL:[NSURL URLWithString:audioMg.image] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        cell.imageViewHook.image = [UIImage imageNamed:@"placeholder"];
        //热门
        if ([self.numberComeIn isEqualToString:@"5"]) {
            cell.labelTitle.text = [NSString stringWithFormat:@"%@",audioMg.title];
            cell.labelChapters.text = [NSString stringWithFormat:@"%@",audioMg.album];
            cell.butShare.hidden = NO;
            if (_LCPlayer.selectedIndex == indexPath.row && [[LCHistoryDataManager loadOneSongsData]  isEqualToString:cell.labelTitle.text]&&[cell.labelChapters.text isEqualToString:_LCPlayer.playingSong.album]) {
                [cell clickOnThisSongToPlay:YES];
                lastClickRow = indexPath.row;
            }else{
                [cell clickOnThisSongToPlay:NO];
            }
        }
        //讲员
        if ([self.numberComeIn isEqualToString:@"6"]) {
            cell.labelTitle.text = [NSString stringWithFormat:@"%@",audioMg.singerName];
            cell.labelChapters.text = [NSString stringWithFormat:@"%@个专辑%@篇讲道",audioMg.total_album,audioMg.total_song];
            cell.butShare.hidden = YES;
        }
        if ([self.numberComeIn isEqualToString:@"7"]) {
            cell.labelTitle.text = [NSString stringWithFormat:@"%@",audioMg.title];
            cell.labelChapters.text = [NSString stringWithFormat:@"%@个专辑",audioMg.total_album];
            cell.butShare.hidden = YES;
        }
        if ([self.numberComeIn isEqualToString:@"8"]) {
            cell.labelTitle.text = [NSString stringWithFormat:@"%@",audioMg.title];
            cell.labelChapters.text = [NSString stringWithFormat:@"%@个讲道",audioMg.total_music];
            cell.butShare.hidden = YES;
        }
    }
    cell.butShare.tag = indexPath.row;
    [cell.butShare addTarget:self action:@selector(clickButShare:) forControlEvents:UIControlEventTouchUpInside];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
#pragma mark - 单元格的点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //机构和类别
    if (([self.numberComeIn isEqualToString:@"7"]||[self.numberComeIn isEqualToString:@"8"])) {
        LSZPriestPreachedAudioMg * audioMg = nil;
        audioMg =self.mutArrayData[indexPath.row];

        LSZThemesAlbumsVC * vc = [[LSZThemesAlbumsVC alloc]init];
        vc.titleStr = audioMg.title;

        if ([self.numberComeIn isEqualToString:@"7"]) {
            vc.typeStr = @"jigou";
        }
        if ([self.numberComeIn isEqualToString:@"8"]) {
            vc.typeStr = @"fenlei";
        }
        vc.optStr = @"2";
        vc.parentId = audioMg.id_id;
        if ([self.numberComeIn isEqualToString:@"7"]) {
            vc.lastClassNumberRow = @"3";
        }
        if ([self.numberComeIn isEqualToString:@"8"]) {
            vc.lastClassNumberRow = @"4";
        }
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([self.numberComeIn isEqualToString:@"6"])
        {
        //讲员的详情
        LSZPriestPreachedAudioMg * audioMg = nil;
        audioMg =self.mutArrayData[indexPath.row];

        LSZPlayThemeVC * vc = [[LSZPlayThemeVC alloc]init];
        vc.titleStr = audioMg.singerName;
        vc.typeStr = @"jiangyuan";
        vc.optStr = @"2";
        vc.parentId = audioMg.id_id;
        vc.lastPageNumberRow = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        vc.lastClassNumberRow = @"2";
        [self.navigationController pushViewController:vc animated:YES];
        }
#pragma mark - 诗歌排行榜2  音频是5
    if([self.numberComeIn isEqualToString:@"5"]){
        LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
        _LCPlayer.songs = playlistTest.allSongs;
        if([self.numberComeIn isEqualToString:@"5"]){
            _LCPlayer.valueDistinguish = @"6_1";
        }
        [_LCPlayer playAtIndex:indexPath.row isSelectPlay:YES];//播放歌曲
        NSInteger lastRow = lastClickRow;
        lastClickRow = (NSInteger)indexPath.row;
        if (lastRow > 0||lastRow == 0) {
            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:lastRow inSection:0];
            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        }
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    }
}
#pragma mark - _______________下面都是请求____________________
#pragma mark - 牧师讲道的音频下几个小分类的请求_数据请求________________
#pragma mark - 查询有没有数据
-(void)QueryTheCachePriestForTheAudioData :(NSString *)type
{
    //jiangdao_yinpin
    __weak typeof(self) weakSelf = self;
    NSString * strType = [NSString stringWithFormat:@"%@_%@",jiangdao_yinpin,type];
    [LSZCacheHandling initWithfindPlist:strType :^(BOOL isOk, NSDictionary * dic) {
        if (isOk == YES) {
            LSZPriestPreachedAudioManager * MG  = [[LSZPriestPreachedAudioManager alloc]initWithDicPriestPreachedAudioManager:dic type:type value:@"1"];

            [weakSelf.mutArrayData removeAllObjects];
            [weakSelf.mutArrayData setArray:MG.mutDataArray];

            if ([weakSelf.numberComeIn isEqualToString:@"5"]) {
                [weakSelf.mutAllOriginalArrayData removeAllObjects];
                [weakSelf.mutAllOriginalArrayData setArray:MG.historyArrayData];
            }
            //播放
            if([weakSelf.numberComeIn isEqualToString:@"5"]){
                NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
                if ([distinguishValue isEqualToString:@"6_1"]) {
                    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                    _LCPlayer.songs = playlistTest.allSongs;
                }
            }

            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [self.tableViewAudio reloadData];
            }];
        }else{
            [self loadMusicPriestPreached:type];
        }
    }];
}
#pragma mark - 请求的数据
- (void)loadMusicPriestPreached:(NSString *)type
{
    __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithSaysAudio:[NSString stringWithFormat:@"%ld",(long)self.numberPage] type:type :^(BOOL isOK, NSString * str, LSZPriestPreachedAudioManager * AudioManager) {
        if (isOK == YES) {
            if (weakSelf.numberPage == 1) {
                [weakSelf.mutArrayData removeAllObjects];
                [weakSelf.mutArrayData setArray:AudioManager.mutDataArray];
                if ([weakSelf.numberComeIn isEqualToString:@"5"]) {
                    [weakSelf.mutAllOriginalArrayData removeAllObjects];
                    [weakSelf.mutAllOriginalArrayData setArray:AudioManager.historyArrayData];
                }
            }else{
                [weakSelf.mutArrayData addObjectsFromArray:AudioManager.mutDataArray];
                if ([weakSelf.numberComeIn isEqualToString:@"5"]) {
                    [weakSelf.mutAllOriginalArrayData addObjectsFromArray:AudioManager.historyArrayData];
                }
            }
            if([weakSelf.numberComeIn isEqualToString:@"5"]){
                NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
                if ([distinguishValue isEqualToString:@"6_1"]) {
                    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                    _LCPlayer.songs = playlistTest.allSongs;
                }
            }
            [weakSelf.tableViewAudio reloadData];
        }else{
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@",str]];
            [SVProgressHUD dismissWithDelay:1];
        }
    }];
}
#pragma mark - 牧师讲道 音频下的分类选择
-(void)clickChooseAudio:(UIButton *)but
{
    if(but.tag == 10){
        if(self.AudioNumberClass == 1){
            return;
        }
        self.AudioNumberClass = 1;
        [self AudioNumberClassChooseBut];
    }else if (but.tag == 11){
        if(self.AudioNumberClass == 2){
            return;
        }
        self.AudioNumberClass = 2;
        [self AudioNumberClassChooseBut];
    }else if (but.tag == 12){
        if(self.AudioNumberClass == 3){
            return;
        }
        self.AudioNumberClass = 3;
        [self AudioNumberClassChooseBut];
    }else{
        if(self.AudioNumberClass == 4){
            return;
        }
        self.AudioNumberClass = 4;
        [self AudioNumberClassChooseBut];
    }
}
#pragma mark - 在牧师讲道下的音频下   下面几个小类的选择
-(void)AudioNumberClassChooseBut
{
    self.viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO;
    UIButton * butonHot = [self.viewSmall viewWithTag:10];
    UIButton * butonSpeaker = [self.viewSmall viewWithTag:11];
    UIButton * butonMechanism = [self.viewSmall viewWithTag:12];
    UIButton * butonClass = [self.viewSmall viewWithTag:13];
    if (self.AudioNumberClass == 1) {
        //选择热门
        butonHot.backgroundColor = navColor;
        [butonHot setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        butonSpeaker.backgroundColor = [UIColor whiteColor];
        [butonSpeaker setTitleColor:navColor forState:UIControlStateNormal];
        butonMechanism.backgroundColor = [UIColor whiteColor];
        [butonMechanism setTitleColor:navColor forState:UIControlStateNormal];
        butonClass.backgroundColor = [UIColor whiteColor];
        [butonClass setTitleColor:navColor forState:UIControlStateNormal];
        self.numberPage = 1;
        self.numberComeIn = @"5";
        //这个地方添加它  是为了解决  从讲员 机构 类别他们的子界面播放之后  回到热门随机播放出现问题
        LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
        _LCPlayer.songs = playlistTest.allSongs;
        [self QueryTheCachePriestForTheAudioData:@"hotmusic"];
    }else if (self.AudioNumberClass == 2){
        //讲员
        butonHot.backgroundColor = [UIColor whiteColor];
        [butonHot setTitleColor:navColor forState:UIControlStateNormal];
        butonSpeaker.backgroundColor = navColor;
        [butonSpeaker setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        butonMechanism.backgroundColor = [UIColor whiteColor];
        [butonMechanism setTitleColor:navColor forState:UIControlStateNormal];
        butonClass.backgroundColor = [UIColor whiteColor];
        [butonClass setTitleColor:navColor forState:UIControlStateNormal];
        self.numberPage = 1;
        self.numberComeIn = @"6";
        [self QueryTheCachePriestForTheAudioData:@"jiangyuan"];
    }else if (self.AudioNumberClass == 3){
        //机构
        butonHot.backgroundColor = [UIColor whiteColor];
        [butonHot setTitleColor:navColor forState:UIControlStateNormal];
        butonSpeaker.backgroundColor = [UIColor whiteColor];
        [butonSpeaker setTitleColor:navColor forState:UIControlStateNormal];
        butonMechanism.backgroundColor = navColor;
        [butonMechanism setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        butonClass.backgroundColor = [UIColor whiteColor];
        [butonClass setTitleColor:navColor forState:UIControlStateNormal];
        self.numberPage = 1;
        self.numberComeIn = @"7";
        [self QueryTheCachePriestForTheAudioData:@"jigou"];
    }else  {
        //类别
        butonHot.backgroundColor = [UIColor whiteColor];
        [butonHot setTitleColor:navColor forState:UIControlStateNormal];
        butonSpeaker.backgroundColor = [UIColor whiteColor];
        [butonSpeaker setTitleColor:navColor forState:UIControlStateNormal];
        butonMechanism.backgroundColor = [UIColor whiteColor];
        [butonMechanism setTitleColor:navColor forState:UIControlStateNormal];
        butonClass.backgroundColor = navColor;
        [butonClass setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.numberPage = 1;
        self.numberComeIn = @"8";
        [self QueryTheCachePriestForTheAudioData:@"fenlei"];
    }
}
#pragma mark - 赞美诗歌的分类数据请求___________________________
#pragma mark - 赞美诗歌的分类缓存查询
 
-(NSMutableArray *)mutAllOriginalArrayData
{
    if (_mutAllOriginalArrayData == nil) {
        _mutAllOriginalArrayData = [[NSMutableArray alloc]init];
    }
    return _mutAllOriginalArrayData;
}
#pragma mark - 上啦加载更多  下拉刷新
-(void)tableviewData
{
    //表的上下拉
    self.tableViewAudio.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 进入刷新状态后会自动调用这个block
            self.numberPage = 1;
            //讲道音频下的几个小分类
            if ([self.numberComeIn isEqualToString:@"5"]) {
                [self QueryTheCachePriestForTheAudioData:@"hotmusic"];
            }
            if ([self.numberComeIn isEqualToString:@"6"]) {
                [self QueryTheCachePriestForTheAudioData:@"jiangyuan"];
            }
            if ([self.numberComeIn isEqualToString:@"7"]) {
                [self QueryTheCachePriestForTheAudioData:@"jigou"];
            }
            if ([self.numberComeIn isEqualToString:@"8"]) {
                [self QueryTheCachePriestForTheAudioData:@"fenlei"];
            }
            [self.tableViewAudio.mj_header endRefreshing];
        });
    }];
    // 上拉刷新
    self.tableViewAudio.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            // 进入刷新状态后会自动调用这个block
            self.numberPage++;

            if ([self.numberComeIn isEqualToString:@"5"]) {
                [self loadMusicPriestPreached:@"hotmusic"];
            }
            if ([self.numberComeIn isEqualToString:@"6"]) {
                [self loadMusicPriestPreached:@"jiangyuan"];
            }
            if ([self.numberComeIn isEqualToString:@"7"]) {
                [self loadMusicPriestPreached:@"jigou"];
            }
            if ([self.numberComeIn isEqualToString:@"8"]) {
                [self loadMusicPriestPreached:@"fenlei"];
            }
            [self.tableViewAudio.mj_footer endRefreshing];
        });
    }];
}
#pragma mark - 分享弹出来的view
-(void)setViewSharePopover
{
    [LSZSpecialPackaging initAlterView:self.view :^(UIView * viewBack,UIView * viewLow, UIButton * buttonFriends, UIButton * buttonFriendsCircle, UIButton * buttonDownload, UIButton * butCancel) {
        _viewSharePopover = viewBack;
        [self.view bringSubviewToFront:_viewSharePopover];
        [self.tableViewAudio bringSubviewToFront:_viewSharePopover];

        self.viewLow = viewLow;
        [self.view bringSubviewToFront:self.viewLow];
        [self.tableViewAudio bringSubviewToFront:self.viewLow];

        self.butCancel = butCancel;
        [self.view bringSubviewToFront:self.butCancel];
        [self.tableViewAudio bringSubviewToFront:self.butCancel];

        self.viewSharePopover.hidden = YES;
        self.viewLow.hidden = YES;
        self.butCancel.hidden = YES;
        [LCFloatingWindow sharedInstance].hidden = NO;

        [buttonFriends addTarget:self action:@selector(clickShareWeiXin) forControlEvents:UIControlEventTouchUpInside];
        [buttonFriendsCircle addTarget:self action:@selector(clickShareWeiXinFriendsCircle) forControlEvents:UIControlEventTouchUpInside];
        [buttonDownload addTarget:self action:@selector(clickDoenload) forControlEvents:UIControlEventTouchUpInside];
        [butCancel addTarget:self action:@selector(clickButCancel) forControlEvents:UIControlEventTouchUpInside];
    }];
}
#pragma mark - 点击的哪一行的要分享
-(void)clickButShare :(UIButton *)but
{
    self.shareAndDownloadNumberRow = but.tag;
    if(self.numberRow == but.tag){
        self.viewSharePopover.hidden = YES;
        self.viewLow.hidden = YES;
        self.butCancel.hidden = YES;
        [LCFloatingWindow sharedInstance].hidden = NO;
        self.numberRow = -1;
    }else{
        self.viewSharePopover.hidden = NO;
        self.viewLow.hidden = NO;
        self.butCancel.hidden = NO;
        [LCFloatingWindow sharedInstance].hidden = YES;
        self.numberRow = but.tag;
    }
}
#pragma mark - 点击微信分享好友
-(void)clickShareWeiXin
{
    NSString * strUrl = [[NSString alloc]init];
    NSString * strTitle = [[NSString alloc]init];
#pragma mark - 赞美诗的排行榜的数据加载
    LSZPriestPreachedAudioMg * audioMg = nil;
    audioMg =self.mutArrayData[self.shareAndDownloadNumberRow];
    strUrl = audioMg.fileUrl;
    strTitle = audioMg.title;
    NSArray* imageArray = @[[UIImage imageNamed:@"placeholder"]];
    [LSZSpecialPackaging shareWXWithViewController:self imageArray:imageArray url:strUrl title:strTitle contentMessage:@"" type:0];
    [self clickButCancel];
}
#pragma mark - 点击微信分享朋友圈
-(void)clickShareWeiXinFriendsCircle
{
    NSString * strUrl = [[NSString alloc]init];
    NSString * strTitle = [[NSString alloc]init];
    LSZPriestPreachedAudioMg * audioMg = nil;
    audioMg =self.mutArrayData[self.shareAndDownloadNumberRow];
    strUrl = audioMg.fileUrl;
    strTitle = audioMg.title;
    NSArray* imageArray = @[[UIImage imageNamed:@"placeholder"]];
    [LSZSpecialPackaging shareWXWithViewController:self imageArray:imageArray url:strUrl title:strTitle contentMessage:@"" type:1];
    [self clickButCancel];
}
#pragma mark - 点击下载的按钮
-(void)clickDoenload
{
    LSZPriestPreachedAudioMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    NSDictionary *json = [audioMg yy_modelToJSONObject];
    JKSongsMessStatus *song = [JKSongsMessStatus yy_modelWithJSON:json];
    [kNetworkTool downloadSongWithUrl:song];
    [self clickButCancel];
    NSLog(@"点击下载的按钮的点击事件");
}
#pragma mark - 分享或者下载的view   下落
-(void)clickButCancel
{
    _viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO;
    self.numberRow = -1;
}
#pragma mark - 新的分享和收藏
-(void)clickMoveMusicList:(UIButton *)butMove
{
    self.cliclMoveWhereRow = butMove.tag - 1;
    LSZleagueTableMg * mg = nil;
    mg = self.mutArrayData[self.cliclMoveWhereRow];
    LSZPopoverViewController * vc = [[LSZPopoverViewController alloc]init];
    [vc show];
    [vc selectIndexRowWith:2];//布局
    [vc getMusicId:mg.id_id];
    [vc distinguishType:@"3"];
    [vc fromWhichInterface:@"LSZPraisePoetryChartsViewController"];
}
#pragma mark  - 分享
-(void)addNSNotificationCenter
{
    NSString * stringCollection = [NSString stringWithFormat:@"%@Collection",@"LSZPraisePoetryChartsViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MusicListCollection:) name:stringCollection object:nil];//收藏歌曲成功的通知
    NSString * strShare = [NSString stringWithFormat:@"%@",@"LSZPraisePoetryChartsViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationMusicListShare) name:strShare object:nil];//点击分享歌曲的通知
    NSString * strDownload = [NSString stringWithFormat:@"%@Download",@"LSZPraisePoetryChartsViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationMusicListDownload) name:strDownload object:nil];//点击下载的通知
    NSString * stringLogin = [NSString stringWithFormat:@"%@Login",@"LSZPraisePoetryChartsViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationMusicListLogin) name:stringLogin object:nil];//点击收藏  用户没登录
    //安装播放歌曲发生变化的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MusicListPlayerPlayingSongDidChangedNotification:) name:LCMusicPlayerPlayingSongDidChangedNotification object:_LCPlayer];
}
-(void)MusicListCollection:(NSNotification *)notification
{
    NSDictionary * diction = notification.userInfo;
    if ([diction[@"ok"] isEqualToString:@"YES"]) {
        [self setStringWarning:@"收藏成功!"];
    }else{
        [self setStringWarning:diction[@"str"]];
    }
}
- (void)InfoNotificationMusicListShare {
    LSZleagueTableMg * mg = nil;
    mg = self.mutArrayData[self.cliclMoveWhereRow];
    [self shareAudioWithImageArray:@[mg.image] url:mg.fileUrl musicWebURL:mg.shareUrl title:mg.title contentMessage:mg.singerName type:(SSDKContentTypeAudio)];
}
#pragma mark - 下载
-(void)InfoNotificationMusicListDownload
{
    JKSongsMessStatus *songsMessStatus;
    LSZleagueTableMg * mg = nil;
    mg = self.mutArrayData[self.cliclMoveWhereRow];
    NSDictionary *json = [mg yy_modelToJSONObject];
    songsMessStatus = [JKSongsMessStatus yy_modelWithJSON:json];
    [kNetworkTool downloadSongWithUrl:songsMessStatus];//下载歌曲文件
}
#pragma mark - 收到通知  用户未登录
-(void)InfoNotificationMusicListLogin
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }
}
- (void)MusicListPlayerPlayingSongDidChangedNotification:(NSNotification *)notification {
    [self.tableViewAudio reloadData];
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
